package org.zyj.io.example.buf;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;

/**
 * ByteBuf简单使用
 * 了解这几个指针的概念:
 * readerIndex
 * writerIndex
 * capacity
 */
public class NettyByteBuf01 {

    public static void main(String[] args) {
        //创建一个对象, 该对象包含一个数组 arr, 是一个 byte[10]
        //netty的ByteBuf不需要使用flip,进行反转
        ByteBuf buf = Unpooled.buffer(10);
        for (int i = 100; i < 100 + 20; i++) {
            buf.writeByte(i);
        }
        System.out.println("capacity = " + buf.capacity());
        System.out.println("readableBytes = " + buf.readableBytes());
        while (buf.readableBytes() > 0) {
            System.out.println(buf.readByte());//readerIndex会变
        }
    }
}
